package javaBase.javaException;

/**
 * Created by Administrator on 2017/2/23 0023.
 */
public class ExcepTest {
    /**
     * 模拟Bean层，处理业务Logic
     */
    public void ExcA(int i) throws WebException {
        if (i < 10) { //抛出一个自定义异常，用来解析判断等处理
            throw new WebException(ExceptionConstants.Code_0000);
        }
        if (i == 10) {//抛出一个运行时异常，系统自动抛出
            int j = i / 0;
            System.out.println("j=" + j);
        }
    }

    /**
     * 模拟控制层Controller
     */
    public static void main(String[] args) throws WebException {
        ExcepTest e = new ExcepTest();
        try {
            e.ExcA(10);
        } catch (WebException e1) { //这个异常是捕获我们封装的异常
            ExceptionOutput out = new ExceptionOutput(
                    e1.getExceptionCode());
            out.toXML();//写回异常信息给客户端
        } catch (Exception ex) {//一般用来捕获运行时异常
            ExceptionOutput out = new ExceptionOutput(
                    ExceptionConstants.Code_9999);
            out.toXML(); //写回异常信息给客户端
        }
    }
}
